package test
import com.db.Config;
import com.gmongo.GMongo
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import sender.EmailSenderJava;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoException;
class TestGmongodb {
	
	static main(args) {
		
		// Instantiate a com.gmongo.GMongo object instead of com.mongodb.Mongo
		// The same constructors and methods are available here
		def mongo = new GMongo('192.168.56.101',18020)
		// Get a db reference in the old fashion way
		def db = mongo.getDB("gmongo")
		
		
		// Collections can be accessed as a db property (like the javascript API)
		assert db.myCollection instanceof com.mongodb.DBCollection
		// They also can be accessed with array notation
		assert db['my.collection'] instanceof com.mongodb.DBCollection
		
		
		// Insert a document
		db.languages.insert([name: 'Groovy'])
		// A less verbose way to do it
		db.languages.insert(name: 'Ruby')
		// Yet another way
		db.languages << [name: 'Python']
		
		// Insert a list of documents
		db.languages << [[name: 'Javascript', type: 'prototyped'], [name: 'Ioke', type: 'prototyped']]
		
		def statics = ['Java', 'C', 'VB']
		
		statics.each {
			db.languages << [name: it, type: 'static']
		}
		
		// Finding the first document
		def lang = db.languages.findOne(name: 'Groovy')
		println 1
		
		//创建索引，排序
		
		def jmongo =new Mongo(Config.dbip, Config.dbport);
		DB jdb = jmongo.getDB("gmongo");
		DBCollection coll2 = jdb.getCollection("languages");
	//	coll2.createIndex(new BasicDBObject("name", 1))
		def a =coll2.find().sort(new BasicDBObject("_id", 1));
		a.each {  println it }
		
		 
	}
}
